/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rbh.risk.dao.impl;

import com.rbh.risk.dao.SeverityLevelDao;
import com.rbh.risk.entity.SeverityLevel;
import com.rbh.risk.support.SessionFactorySupport;
import java.util.List;
import org.hibernate.Query;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

@Repository("severityLevelDao")
public class SeverityLevelDaoImpl extends SessionFactorySupport implements SeverityLevelDao {

    @Override
    public void insert(SeverityLevel severityLevel) throws DataAccessException {
        try{
            super.getSessionFactory().getCurrentSession().save(severityLevel);
        } catch(Exception ex){
            throw ex;
        }
    }

    @Override
    public void update(SeverityLevel severityLevel) throws DataAccessException {
        try{
            super.getSessionFactory().getCurrentSession().update(severityLevel);
        } catch(Exception ex){
            throw ex;
        }
    }

    @Override
    public void delete(SeverityLevel severityLevel) throws DataAccessException {
        try{
            super.getSessionFactory().getCurrentSession().delete(severityLevel);
        } catch(Exception ex){
            throw ex;
        }
    }

    @Override
    public SeverityLevel getById(Integer severityLevelId) throws DataAccessException {
        SeverityLevel result = null;
        try {
            result = (SeverityLevel) super.getSessionFactory().getCurrentSession().get(SeverityLevel.class, severityLevelId.byteValue());
        } catch (Exception ex) {
            throw ex;
        }
        return result;
    }

    @Override
    public List<SeverityLevel> getAll() throws DataAccessException {
        List<SeverityLevel> results = null;
        try {
            Query query = super.getSessionFactory().getCurrentSession().createQuery("from " + SeverityLevel.class.getName());
            results = query.setCacheable(true).list();
        } catch (Exception ex) {
            throw ex;
        }
        return results;
    }
    
}
